package cn.gson.springboot.controller;

import cn.gson.springboot.model.dao.ApprovalDao;
import cn.gson.springboot.model.mapper.ApprovalMapper;
import cn.gson.springboot.model.pojos.Approval;
import cn.gson.springboot.model.pojos.Employee;
import cn.gson.springboot.model.service.ApprovalService;
import cn.gson.springboot.model.vo.ApprovalVo;
import cn.gson.springboot.model.vo.QuotationVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ApprovalController {
    @Autowired
    ApprovalService appService;

    @Autowired
    HttpSession session;

    //查询审批表分页
    @RequestMapping("/app-list")
    @ResponseBody
    public Map<String,Object> appList(Integer page,Integer size,Integer type,Integer num,Integer empId,String appTheme){
        Page<Object> objects = PageHelper.startPage(page, size);
        //Employee emp =(Employee) session.getAttribute("emp");
        List<Approval> Approval = appService.selectAllApproval(type,num,empId,appTheme);
        Map<String,Object> map = new HashMap<>();
        map.put("total",objects.getTotal());
        map.put("rows",Approval);
        return map;
    }
    //查询报价单待审批表
    @RequestMapping("/app-quo")
    @ResponseBody
    public Approval appByQuoId(Integer quoId){
        Approval app = appService.selectApprovalByQuoId(quoId);
        return app;
    }
    //查询出差待审批表
    @RequestMapping("/app-bus")
    @ResponseBody
    public Approval appByBusId(Integer businessId){
        Approval app = appService.selectApprovalByBusId(businessId);
        return app;
    }
    //查询采购待审批表
    @RequestMapping("/app-pur")
    @ResponseBody
    public Approval appByPurId(Integer purId){
        Approval app = appService.selectApprovalByPurId(purId);
        return app;
    }
    //查询合同待审批表
    @RequestMapping("/app-con")
    @ResponseBody
    public Approval appByConId(Integer conId){
        Approval app = appService.selectApprovalByConId(conId);
        return app;
    }
    //查询付款计划待审批表
    @RequestMapping("/app-pay")
    @ResponseBody
    public Approval appByPayId(Integer payId){
        Approval app = appService.selectApprovalByPayPlanId(payId);
        return app;
    }
    //根据审批表Id查询审批表
    @RequestMapping("/app-id")
    @ResponseBody
    public Approval appByAppId(Integer appId){
        Approval app = appService.selectApprovalByAppId(appId);
        Approval approval = appService.selectAppByAppIdAndClassify(app);
        return approval;
    }
    //根据审批表状态查询审批表
    @RequestMapping("/app-status-list")
    @ResponseBody
    public Map<String,Object> appStatusList(Integer page,Integer size,Integer appStatus){
        Page<Object> objects = PageHelper.startPage(page, size);
        //Employee emp =(Employee) session.getAttribute("emp");
        List<Approval> Approval = appService.selectApprovalByStatus(appStatus);
        Map<String,Object> map = new HashMap<>();
        map.put("total",objects.getTotal());
        map.put("rows",Approval);
        return map;
    }
    //查询待审批表
    @RequestMapping("/app-status-one-list")
    @ResponseBody
    public Map<String,Object> appStatusAllList(Integer page,Integer size){
        Page<Object> objects = PageHelper.startPage(page, size);
        List<Approval> Approval = appService.selectApprovalByStatus(1);
        Map<String,Object> map = new HashMap<>();
        map.put("total",objects.getTotal());
        map.put("rows",Approval);
        return map;
    }
    //根据审批表状态查询审批表
    @RequestMapping("/app-theme-list")
    @ResponseBody
    public Map<String,Object> appThemeList(Integer page,Integer size,String appTheme){
        Page<Object> objects = PageHelper.startPage(page, size);
        //Employee emp =(Employee) session.getAttribute("emp");
        List<Approval> Approval = appService.selectApprovalByTheme(appTheme);
        Map<String,Object> map = new HashMap<>();
        map.put("total",objects.getTotal());
        map.put("rows",Approval);
        return map;
    }

    @RequestMapping("/save-approval")
    @ResponseBody
    public void saveApproval(@RequestBody ApprovalVo vo){
        appService.saveApproval(vo);
    }

}
